/*    */ package handling.channel;
/*    */ 
/*    */ import com.alibaba.druid.pool.DruidPooledConnection;
/*    */ import database.DatabaseConnection;
/*    */ import java.sql.PreparedStatement;
/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.util.LinkedList;
/*    */ import java.util.List;
/*    */ 
/*    */ 
/*    */ public class MapleDojoRanking
/*    */ {
/* 14 */   private static final MapleDojoRanking instance = new MapleDojoRanking();
/* 15 */   private final List<DojoRankingInfo> ranks = new LinkedList<>();
/*    */   
/*    */   public static MapleDojoRanking getInstance() {
/* 18 */     return instance;
/*    */   }
/*    */   
/*    */   public List<DojoRankingInfo> getRank() {
/* 22 */     return this.ranks;
/*    */   }
/*    */   
/*    */   public void load(boolean reload) {
/* 26 */     if (reload) {
/* 27 */       this.ranks.clear();
/*    */     }
/* 29 */     if (!this.ranks.isEmpty()) {
/*    */       return;
/*    */     }
/*    */ 
/*    */     
/* 34 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/* 35 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM dojorankings ORDER BY `rank` DESC LIMIT 50");
/* 36 */       ResultSet rs = ps.executeQuery();
/* 37 */       while (rs.next()) {
/* 38 */         DojoRankingInfo rank = new DojoRankingInfo(rs.getShort("rank"), rs.getString("name"), rs.getLong("time"));
/* 39 */         this.ranks.add(rank);
/*    */       } 
/* 41 */       ps.close();
/* 42 */       rs.close();
/* 43 */     } catch (SQLException e) {
/* 44 */       System.err.println("Error handling dojo rankings: " + e);
/*    */     } 
/*    */   }
/*    */   
/*    */   public static class DojoRankingInfo
/*    */   {
/*    */     private final String name;
/*    */     private final short rank;
/*    */     private final long time;
/*    */     
/*    */     public DojoRankingInfo(short rank, String name, long time) {
/* 55 */       this.rank = rank;
/* 56 */       this.name = name;
/* 57 */       this.time = time;
/*    */     }
/*    */     
/*    */     public short getRank() {
/* 61 */       return this.rank;
/*    */     }
/*    */     
/*    */     public String getName() {
/* 65 */       return this.name;
/*    */     }
/*    */     
/*    */     public long getTime() {
/* 69 */       return this.time;
/*    */     }
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\handling\channel\MapleDojoRanking.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */